package com.kude.service;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kude.service.security.MD5;
import com.kude.util.BeanFactory;

import com.kude.entity.Administrator;
import com.kude.manager.AdministratorManager;
import com.kude.manager.OperException;

public class LoginService {
	
	private static final Logger logger = LoggerFactory.getLogger(LoginService.class.getName());
	private AdministratorManager administratorManager;
	/**
	 * 验证普通用户登录
	 * @param userName
	 * @param password
	 * @throws SecurityException 
	 */
	public boolean validate(String userName,String password) {
		try {
			List<Administrator> admin =administratorManager.find(0,1,Restrictions.eq(Administrator.ADMIN_NAME, userName),Restrictions.eq(Administrator.ADMIN_PASSWORD, MD5.encode(password)));
			if(admin.size() == 1) {
					return true;
			}
		} catch (OperException e) {
			logger.error("用户查询失败",e);
		}
		return false;
	}
	public void setAdministratorManager(AdministratorManager administratorManager) {
		this.administratorManager = administratorManager;
	}
		

}
